/*global lightAppJssdk*/
/*eslint no-undef: "error"*/


/**
 * @name: alert
 * @msg: 弹出提示框，用户点击后返回
 * @param {Object} message: "这是一个弹窗", title: "提示",//可传空 buttonName: "收到" 
 * @return {*}
 */
export function alert(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.alert && lightAppJssdk.notification.alert ({
      ...opts,
      success:resolve,
      //onSuccess 将在点击 button 之后回调
      /*回调*/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: confirm
 * @msg: 确认提示框，用户点击后返回用户点击的按钮。
 * @param {Object} message: "这是一个弹窗", title: "提示",//可传空 buttonLabels: ['确定', '取消'],
 * @return {*}
 */
export function confirm(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.confirm && lightAppJssdk.notification.confirm ({
      ...opts,
      success:resolve,
      //onSuccess 将在点击 button 之后回调
      /* 
      { buttonIndex: 0 //被点击按钮的索引值，Number 类型，从 0 开始 }
      */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: prompt
 * @msg: 确认提示框——输入框，用户点击后返回用户点击的按钮。
 * @param {Object} message: "请输入你的姓名？", title: "提示", buttonLabels: ['提交’, '取消'],
 * @return {*}
 */
export function prompt(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.prompt && lightAppJssdk.notification.prompt ({
      ...opts,
      success:resolve,
      //onSuccess 将在点击 button 之后回调
      /* 
      {
        buttonIndex: 0, //被点击按钮的索引值，Number 类型，从 0 开始
        value: '' //输入的值
      }
      */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: vibrate
 * @msg: 震动
 * @param {Object} duration: 300, //震动时间，android 可配置 iOS 忽略
 * @return {*}
 */
export function vibrate(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.vibrate && lightAppJssdk.notification.vibrate ({
      ...opts,
      success:resolve,
      //onSuccess 
      /*  回调    */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: showPreloader
 * @msg: 等待蒙版显示（显示浮层，请和 hidePreloader 配对使用
 * @param {Object} text: "使劲加载中..", //loading 显示的字符，空表示不显示文字
 * @return {*}
 */
export function showPreloader(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.showPreloader && lightAppJssdk.notification.showPreloader ({
      ...opts,
      success:resolve,
      //onSuccess 
      /*  回调    */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: hidePreloader
 * @msg: 等待蒙版隐藏
 * @param {} 
 * @return {*}
 */
export function hidePreloader() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.hidePreloader && lightAppJssdk.notification.hidePreloader ({
      success:resolve,
      //onSuccess 
      /*  回调    */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: toast
 * @msg: 弱提示
 * @param {} text: String, //提示信息
 * @return {*}
 */
export function toast(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.toast && lightAppJssdk.notification.toast ({
      ...opts,
      success:resolve,
      //onSuccess 
      /*  回调    */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: actionSheet
 * @msg: 选择器——单选列表
 * @param {Object} title: "这是一个选择器", //标题, cancelButton: '取消', //取消按钮文本, otherButtons: ["选项一","选项二","选项三","选项四"],
 * @return {*}
 */
export function actionSheet(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.actionSheet && lightAppJssdk.notification.actionSheet ({
      ...opts,
      success:resolve,
      //onSuccess 将在点击 button 之后回调
      /*  {
            buttonIndex: 0 //被点击按钮的索引值，Number，从 0 开始, 
                取消按钮为-1
          }    
      */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: getLocation
 * @msg: 位置——获取位置信息。
 * @param {*}
 * @return {*}
 */
export function getLocation() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.notification && lightAppJssdk.notification.getLocation && lightAppJssdk.notification.getLocation ({
      success:resolve,
      //onSuccess 
      /*  { 
            "latitude": "119.230222", 
            "longitude": "23.222244", 
            "detailAddress": "南京市玄武区钟灵街紫金大厦", 
            "cityName":"南京市",——城市名称
            "region": "玄武区"——区域名称
          }   
      */
      fail:reject, //错误返回
    });
  })
}


/**
 * @name: getDistance
 * @msg:  距离——目的坐标距离当前位置距离
 * @param {Object} arg: '31.783546,118.970835';
 * @return {*}
 */
export function getDistance(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.map && lightAppJssdk.map.getDistance && lightAppJssdk.map.getDistance ({
      ...opts,
      success:resolve,
      //onSuccess
      /* 成功回调  */
      fail:reject, //错误返回
    });
  })
}


/**
 * @name: call
 * @msg: 打电话——唤起拨打电话。
 * @param {Object} phone:"15555555555",
 * @return {*}
 */
export function call(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.device && lightAppJssdk.device.call && lightAppJssdk.device.call ({
      ...opts,
      success:resolve,
      //onSuccess
      /* 成功回调  */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: message
 * @msg: 发短信——唤起发送短信
 * @param {Object} phone:"15555555555",
 * @return {*}
 */
export function message(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.device && lightAppJssdk.device.message && lightAppJssdk.device.message ({
      ...opts,
      success:resolve,
      //onSuccess
      /* 成功回调  */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: mail
 * @msg: 发邮件——唤起发送邮件
 * @param {Object} email:"邮箱地址",
 * @return {*}
 */
export function mail(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.device && lightAppJssdk.device.mail && lightAppJssdk.device.mail ({
      ...opts,
      success:resolve,
      //onSuccess
      /* 成功回调  */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: uuid
 * @msg: 设备唯一标示
 * @param {*}
 * @return {*}
 */
export function uuid() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.device && lightAppJssdk.device.uuid && lightAppJssdk.device.uuid ({
      success:resolve,
      //onSuccess
      /* 成功回调  uuid 设备唯一标示*/
      fail:reject, //错误返回
    });
  })
}


/**
 * @name: networkType
 * @msg: 当前网络类型
 * @param {*}
 * @return {*}
 */
export function networkType() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.device && lightAppJssdk.device.networkType && lightAppJssdk.device.networkType ({
      success:resolve,
      //onSuccess
      /* 成功回调  result 值: wifi、2g、3g、4g、unknown、none，none 表示离线 */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: scan
 * @msg: 扫一扫
 * @param {*}
 * @return {*}
 */
export function scan() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.device && lightAppJssdk.device.scan && lightAppJssdk.device.scan ({
      success:resolve,
      //onSuccess
      /* 成功回调  text 扫码内容 */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: chooseImage
 * @msg: 媒体资源——图片选择
 * @param {Object} arg:"图片占内存大小，单位是 kb",
 * @return {*}
 */
export function chooseImage(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.media && lightAppJssdk.media.chooseImage && lightAppJssdk.media.chooseImage ({
      ...opts,
      success:resolve,
      //onSuccess
      /* {
            result：true/false 成功标识
            picPath：图片的路径，,数组类型
        }
       */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: chooseVideo
 * @msg: 媒体资源——视频选择
 * @param {*}
 * @return {*}
 */
export function chooseVideo() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.media && lightAppJssdk.media.chooseVideo && lightAppJssdk.media.chooseVideo ({
      success:resolve,
      //onSuccess
      /* {
            result：true/false 成功标识
            videoPath：视频的路径，,数组类型
        }
       */
      fail:reject, //错误返回
    });
  })
}


/**
 * @name: chooseVideoAndPic
 * @msg: 媒体资源——摄像+拍照+相册选择
 * @param {*} arg:"图片占内存大小，单位是 kb",
 * @return {*}
 */
export function chooseVideoAndPic(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.media && lightAppJssdk.media.chooseVideoAndPic && lightAppJssdk.media.chooseVideoAndPic ({
      ...opts,
      success:resolve,
      //onSuccess
      /* {
            result：true/false 成功标识
            picPath：图片的路径，,数组类型
            videoPath：视频的路径，,数组类型
        }
       */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: startVoice
 * @msg: 音频——开始录音
 * @param {*} 
 * @return {*}
 */
export function startVoice() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.media && lightAppJssdk.media.startVoice && lightAppJssdk.media.startVoice ({
      success:resolve,
      //onSuccess
      /* */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: stopVoice
 * @msg: 音频——完成录音
 * @param {*} 
 * @return {*}
 */
export function stopVoice() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.media && lightAppJssdk.media.stopVoice && lightAppJssdk.media.stopVoice ({
      success:resolve,
      //onSuccess
      /*{
            result：true/false 成功标识
            audioPath：视频的路径，,String 类型
        } */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: playVoice
 * @msg: 音频——播放音频
 * @param {Object} audio:"音频文件路径",
 * @return {*}
 */
export function playVoice(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.media && lightAppJssdk.media.playVoice && lightAppJssdk.media.playVoice({
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: stopPlayVoice
 * @msg: 音频——停止播放
 * @param {*} 
 * @return {*}
 */
export function stopPlayVoice() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.media && lightAppJssdk.media.stopPlayVoice && lightAppJssdk.media.stopPlayVoice ({
      success:resolve,
      //onSuccess
      /* */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: openHide
 * @msg: 页面——打开新的窗口并隐藏导航栏
 * @param {Object} url:’url 地址’,
 * @return {*}
 */
export function openHideBar(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.navigation && lightAppJssdk.navigation.hide && lightAppJssdk.navigation.hide({
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: open
 * @msg: 页面——打开新的窗口并显示导航栏
 * @param {Object} url:’url 地址’, title:’服务’, isgoback:’0’,
 * @return {*}
 */
export function open(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.navigation && lightAppJssdk.navigation.show && lightAppJssdk.navigation.show({
      /*
      isgoback: 0 返回按钮先先执行 goback，goback 无效执行关闭
              1 返回按钮直接关闭页面
       */
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: close
 * @msg: 关闭浏览器窗口——关闭当前浏览器窗口
 * @param {*} 
 * @return {*}
 */
export function close() { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.navigation && lightAppJssdk.navigation.close && lightAppJssdk.navigation.close({
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: encrypt
 * @msg: 加密
 * @param {Object} data:{a:1,b:2}
 * @return {*}
 */
export function encrypt(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.dataUtil && lightAppJssdk.dataUtil.encrypt && lightAppJssdk.dataUtil.encrypt({
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: decrypt
 * @msg: 解密
 * @param {Object} data:{a:1,b:2}
 * @return {*}
 */
export function decrypt(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.dataUtil && lightAppJssdk.dataUtil.decrypt && lightAppJssdk.dataUtil.decrypt({
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: setItem
 * @msg: 存储缓存——存储键值对
 * @param {Object} key: String, //键 value: String, //值
 * @return {*}
 */
export function setItem(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.util && lightAppJssdk.util.setItem && lightAppJssdk.util.setItem({
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: getItem
 * @msg: 存储缓存——根据键获取值
 * @param {Object} key: String, //键
 * @return {*}
 */
export function getItem(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.util && lightAppJssdk.util.getItem && lightAppJssdk.util.getItem({
      ...opts,
      success:resolve,
      //onSuccess
      /*
      {
        key: String, //键
        value: String, //值
      }
      */
      fail:reject, //错误返回
    });
  })
}

/**
 * @name: removeItem
 * @msg: 存储缓存——删除缓存
 * @param {Object} key: String, //键 value: String, //值
 * @return {*}
 */
export function removeItem(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.util && lightAppJssdk.util.removeItem && lightAppJssdk.util.removeItem({
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}


/**
 * @name: request
 * @msg: 请求——网络请求，可跨域执行。
 * @param {Object} 
 * @return {*}
 */
export function request(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.request && lightAppJssdk.request.request && lightAppJssdk.request.request({
      /* 
        data: '{a:1,b:2}'请求参数 ,
        header：'Json 格式 String' ,
        dataType：'返回数据类型' //返回数据格式，默认 json
        url:请求地址
        async:是否同步(true/false)
       */
      ...opts,
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}


/**
 * @name: share
 * @msg: 社交分享
 * @param {Object} 
 * @return {*}
 */
export function share(opts = {}) { 
  return new Promise((resolve, reject) => { 
    lightAppJssdk && lightAppJssdk.util && lightAppJssdk.util.share && lightAppJssdk.util.share({
      /* 
      arg:{ // Json 格式 String
        titleStr : "测试内容的标题";//标题，如果没有赋空值
        contentStr : "这是测试的分享内容";//内容，如果没有赋空值
        shareUrlStr : "http://www.baidu.com";//分享的链接，如果没有赋空值
        imageStr : "http://pic.nipic.com/2007-11-09/2007119122519868_2.jpg";//图片的 url 地址,如果没有赋空值
      }
       */
      arg: {
        titleStr : "",//标题，如果没有赋空值
        contentStr : "",//内容，如果没有赋空值
        shareUrlStr : "",//分享的链接，如果没有赋空值
        imageStr : "",//图片的 url 地址,如果没有赋空值
        ...opts,
      },
      success:resolve,
      //onSuccess
      /**/
      fail:reject, //错误返回
    });
  })
}







